﻿using System.Linq;
using System.Web;
using Concret;

public class Login : HandlerBase
{
	/// <summary>
	/// 登录
	/// </summary>
	/// <param name="acc"></param>
	/// <param name="psw"></param>
	/// <returns></returns>
	[NoLogin]
	public dynamic login(string acc, string psw)
	{
		var user = new Users(DbOp) { Account_Val = acc, Password_Val = psw }.GetByFVs().SingleOrDefault();
		if (user == null) throw new Error("用户不存在或密码错误");

		Response.Cookies.Add(new HttpCookie("acc", acc));
		Response.Cookies.Add(new HttpCookie("psw", psw));

		return null;
	}

	/// <summary>
	/// 清空登录状态
	/// </summary>
	/// <returns></returns>
	[NoLogin]
	public dynamic clear()
	{
		Response.Cookies.Clear();
		return null;
	}
}